@extends('admin.layout.layout')
@section('title','用户管理')
@section('con')
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">用户列表</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <!-- /.panel-heading -->
             <div class="panel-body"> 
               <div class="dataTable_wrapper"> 
                <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                 <div class="row">
                 <form action="{{url('/admin/user/index')}}">
                  <div class="col-sm-6">
                   <div class="dataTables_length" id="dataTables-example_length">
                    <label>显示 
                        <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                            <option value="10" @if(!empty($list['num']) && $list['num'] == 10 ){ selected } @endif)>10</option>
                            <option value="25" @if(!empty($list['num']) && $list['num'] == 25 ){ selected } @endif)>25</option>
                            <option value="50" @if(!empty($list['num']) && $list['num'] == 50 ){ selected } @endif)>50</option>
                            <option value="100" @if(!empty($list['num']) && $list['num'] == 100 ){ selected } @endif)>100</option>
                        </select> 条</label>
                   </div>
                  </div>
                  <div class="col-sm-6">
                   <div id="dataTables-example_filter" class="dataTables_filter">
                    <label>搜索:<input name="keywords" value="{{ $list['keywords'] or ' ' }}" type="search" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" /></label>
                    <button class="btn btn-primary" >查询</button>
                   </div>
                  </div>
                 </div>
                </form>
                 <div class="row">
                  <div class="col-sm-12">
                   <table id="dataTables-example" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dataTables-example_info"> 
                    <thead> 
                        <tr>
                            <th>用户Id</th>
                            <th>用户头像</th>
                            <th>用户名</th>
                            <th>权限</th>
                            <th>用户邮箱</th>
                            <th>操作</th>
                        </tr>
                    </thead> 
                    <tbody> 
                    @foreach($users as $k=>$v)
                         <tr class="gradeA" role="row"> 
                          <td class="sorting_1">{{$v->id}}</td> 
                          <td><img src="{{asset($v->uface)}}" width="50px"></td> 
                          <td>{{$v->uname}}</td>
                          <td>{{$v->auth}}</td> 
                          <td class="center">{{$v->email}}</td> 
                          <td class="center">
                            <button class="btn btn-danger btn-sm delete-btn" >
                                删除
                            </button>
                            <!-- <a href="{{url('/admin/user/edit',['id'=>$v->id])}}" class="btn btn-warning">修改</a> -->
                            <a href="/admin/user/edit?id={{$v->id}}" class="btn btn-warning">修改</a>
                          </td> 
                         </tr>
                    @endforeach
                         
                    </tbody> 
                   </table>
                  </div>
                 </div>
                 <div class="row">
                    <!-- 分页 -->
                    {!! $users->appends($list)->render() !!}
                 </div>
                </div> 
               </div> 
               <!-- /.table-responsive --> 
               
              </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div
</div>
@endsection
@section('js')
   <script type="text/javascript">
    // alert($);
      $.ajaxSetup({
           headers: {
                'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
           }
      });
    
    //绑定单击事件
    $('.delete-btn').click(function(){
         //通过这个删除按钮找到他的先辈级对象里的某个td对象里的内容
         var id = $(this).parents('tr').find('.sorting_1').html();
         //定义一个变量储存当前$this的对象
         var btn = $(this);

         //发送ajax
         $.post('/admin/user/delete',{id:id},function(data){
              // alert('22');
              if(data == 1){
                  //删除成功
                  alert('删除成功');
                  //通过删除的对象找到他的先辈级元素tr 删除了tr
                  btn.parents('tr').remove();
              }else{
                  //删除失败
                  alert('删除失败');
              }
         });
    })
   </script>
@endsection
